package com.rj.bd.reservation.service;

import java.util.List;
import java.util.UUID;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rj.bd.Login.entity.Login;
import com.rj.bd.person.dao.PersonMapper;
import com.rj.bd.person.entity.Person;
import com.rj.bd.reservation.dao.ReservationMapper;
import com.rj.bd.reservation.entity.Reservation;
@Transactional
@Service("reservationService")
public class ReservationServiceImpl implements IReservationService {

	@Autowired
	ReservationMapper reservationMapper;
	@Autowired
	PersonMapper personMapper;
	
	public List<Reservation> selectAll(Page<Reservation> page,Reservation reservation) {
		QueryWrapper<Reservation> queryWrapper = new QueryWrapper<Reservation>();
		
		queryWrapper.eq(true, "state", "1");
		 String pname = reservation.getPerson().getPName();
		System.out.println("*********************"+reservation.getPerson().getPName());
		if(reservation.getPerson().getPName() ==null || reservation.getPerson().getPName().isEmpty()){
			queryWrapper.like(true,"p.pName","");
        }else {
        	queryWrapper.like(true,"p.pName",reservation.getPerson().getPName());
        }
		List<Reservation> list = reservationMapper.selectPage(page, queryWrapper).getRecords();
		return list;
	}

	

	public List<Reservation> selectjiezhong( Page<Reservation> page, Reservation reservation) {
QueryWrapper<Reservation> queryWrapper = new QueryWrapper<Reservation>();
		
		queryWrapper.eq(true, "state", "0");
		 String pname = reservation.getPerson().getPName();
		System.out.println("*********************"+reservation.getPerson().getPName());
		if(reservation.getPerson().getPName() ==null || reservation.getPerson().getPName().isEmpty()){
			queryWrapper.like(true,"p.pName","");
        }else {
        	queryWrapper.like(true,"p.pName",reservation.getPerson().getPName());
        }
		List<Reservation> list = reservationMapper.selectPage(page, queryWrapper).getRecords();
		return list;
	}
	
	
	public void save(Reservation reservation) {
		Person person = reservation.getPerson();
		String pid = UUID.randomUUID().toString();
		String rid = UUID.randomUUID().toString();
		person.setPId(pid);
		
		reservation.setPId(pid);
		reservation.setRId(rid);
		
		System.out.println("-------------------->"+person);
		personMapper.save(person);
		reservationMapper.save(reservation);
		
	}


	public void delete(String rId,String pId) {
		personMapper.delete(pId);
		reservationMapper.delete(rId);
	}



	public void edit(Reservation reservation) {
		Person person = reservation.getPerson();
		personMapper.edit(person);
		reservationMapper.edit(reservation);
	}



	
}
